﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChallengePuzzle.Lib
{
    /// <summary>
    /// 数组累加器
    /// </summary>
    public class PlusSum2 : ChallengePuzzle.Lib.IPlusSum
    {
        int Deepth = 0;

        public int GetPlusSumFor(int Number)
        {
            Deepth++;

            int LessNum = Number % 10;

            if (LessNum!=0)
            {
                PreDC[Deepth]++;

                return PreDC[Deepth];                
            }

            int DivNum1 = Number / 10;

            return GetPlusSumFor(DivNum1);
        }

        public int GetPlusSum(int Number)
        {
            Deepth = 0;

            int LessNum = Number % 10;

            if (LessNum != 0) return ++PreDC[Deepth];
            
            int DivNum = Number / 10;
            
            int Value = GetPlusSumFor(DivNum);

            while (Deepth!=0)
            {
                PreDC[--Deepth] = Value;
            }
            return Value;
        }

        public PlusSum2()
        {
            for (int i = 0; i <= 10; i++)
            {
                PreDC.Add(i,0);
            }
        }

        private Dictionary<int, int> PreDC = new Dictionary<int, int>();






    }
}
